<!--企业-花名册-参建单位查看详情-->
<template>
  <div class="container">
    <topTitle
      :titleText="titleText"
      :back="back"
      @gobackTriser="goBack"
    ></topTitle>
    <div class="mainCon">
      <el-row class="logoStyle">
        <el-col :span="24">
          <img
            src="../../../static/img/company.png"
            alt=""
            class="enterpriseLogo fl"
          />
          <div class="fl titleInfoBox">
            <p class="enterpriseName">
              {{ partUnitsInfo.companyName || '--' }}
            </p>
            <p class="uscc">
              统一社会信用代码：{{ partUnitsInfo.uscc || '--' }}
            </p>
          </div>
        </el-col>
      </el-row>
      <div class="spacing"></div>
      <el-row class="detailInfo">
        <el-row>
          <div class="secondaryTitle secondaryTitleTheme mrB24">基础信息</div>
        </el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple" v-if="isJSAdd == 'COMPANY'">
            <table cellspacing="0" cellpadding="0" class="detailTable">
              <tbody>
                <tr>
                  <td class="title">企业名称</td>
                  <td>{{ partUnitsInfo.companyName || '--' }}</td>
                  <td class="title">统一社会信用代码</td>
                  <td>{{ partUnitsInfo.uscc || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">班组数量</td>
                  <td>{{ total.groupTotal || 0 }}个</td>
                  <td class="title">承包类型</td>
                  <td>{{ partUnitsInfo.contractType || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">企业负责人</td>
                  <td>{{ partUnitsInfo.manager || '--' }}</td>
                  <td class="title">负责人联系电话</td>
                  <td>{{ partUnitsInfo.managerTel || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">总人数</td>
                  <td>
                    <template>
                      <el-link
                        type="primary"
                        @click="toEmployees('')"
                        v-if="total.empTotal > 0"
                        >{{ total.empTotal }}人</el-link
                      >
                      <span v-else>0人</span>
                    </template>
                  </td>
                  <td class="title">在职人员</td>
                  <td>
                    <template>
                      <el-link
                        type="primary"
                        @click="toEmployees('ON_JOB')"
                        v-if="total.onjobEmp"
                        >{{ total.onjobEmp }}人</el-link
                      >
                      <span v-else>0人</span>
                    </template>
                  </td>
                </tr>
                <tr>
                  <td class="title">角色</td>
                  <td>{{ partUnitsInfo.type || '--' }}</td>
                  <td class="title"></td>
                  <td></td>
                </tr>
                <tr>
                  <td class="title">项目名称</td>
                  <td colspan="3">{{ partUnitsInfo.projectName || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">进场时间</td>
                  <td>{{ partUnitsInfo.createTime || '--' }}</td>
                  <td class="title">进退场情况</td>
                  <td>{{ partUnitsInfo.status || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">合同附件</td>
                  <td :colspan="partUnitsInfo.typeId == '10' ? '1' : '3'">
                    <template>
                      <el-link
                        v-if="upLoadFile.length > 0"
                        type="primary"
                        @click="toUploadFile()"
                        >已上传</el-link
                      >
                      <span v-else>未上传</span>
                    </template>
                  </td>
                  <template v-if="partUnitsInfo.typeId == '10'">
                    <td class="title">代发委托附件</td>
                    <td>
                      <template>
                        <span v-if="partUnitsInfo.assignmentFiles.length > 0">
                          <span>已上传</span>
                          <el-link
                            class="seeFile"
                            @click="toUploadFileOnBehalfOf()"
                            >查看</el-link
                          >
                          <contractEnclosureDialog
                            v-if="uploadContractOnBehalfOf"
                            dialogTitle="代发委托附件"
                            :tableData="partUnitsInfo.assignmentFiles"
                            @closeDialog="hiddenDialog"
                          ></contractEnclosureDialog>
                        </span>
                        <span v-else>未上传</span>
                      </template>
                    </td>
                  </template>
                </tr>
                <tr>
                  <td class="title">备注</td>
                  <td colspan="3">
                    {{ (partUnitsInfo.remark || '--') | filterHtml }}
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
          <div class="grid-content bg-purple" v-else>
            <table cellspacing="0" cellpadding="0" class="detailTable">
              <tbody>
                <tr>
                  <td class="title">企业名称</td>
                  <td>{{ partUnitsInfo.companyName || '--' }}</td>
                  <td class="title">统一社会信用代码</td>
                  <td>{{ partUnitsInfo.uscc || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">班组数量</td>
                  <td>{{ total.groupTotal || 0 }}个</td>
                  <td class="title">承包类型</td>
                  <td>{{ partUnitsInfo.contractType || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">企业经营地址</td>
                  <td colspan="3">{{ partUnitsInfo.areaName || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">企业地址</td>
                  <td>{{ partUnitsInfo.address || '--' }}</td>
                  <td class="title">企业法人</td>
                  <td>{{ partUnitsInfo.boss || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">企业负责人</td>
                  <td>{{ partUnitsInfo.manager || '--' }}</td>
                  <td class="title">负责人联系电话</td>
                  <td>{{ partUnitsInfo.managerTel || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">项目经理</td>
                  <td>{{ partUnitsInfo.projectManager || '--' }}</td>
                  <td class="title">项目经理联系电话</td>
                  <td>{{ partUnitsInfo.projectManagerTel || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">参建合同价</td>
                  <td>
                    {{
                      partUnitsInfo.total || partUnitsInfo.total === 0
                        ? partUnitsInfo.total + '元'
                        : '--'
                    }}
                  </td>
                  <td class="title">总人数</td>
                  <td>
                    <template>
                      <el-link
                        type="primary"
                        @click="toEmployees('')"
                        v-if="total.empTotal > 0"
                        >{{ total.empTotal }}人</el-link
                      >
                      <span v-else>0人</span>
                    </template>
                  </td>
                </tr>
                <tr>
                  <td class="title">在职人员</td>
                  <td>
                    <template>
                      <el-link
                        type="primary"
                        @click="toEmployees('ON_JOB')"
                        v-if="total.onjobEmp"
                        >{{ total.onjobEmp }}人</el-link
                      >
                      <span v-else>0人</span>
                    </template>
                  </td>
                  <td class="title">角色</td>
                  <td>{{ partUnitsInfo.type || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">项目名称</td>
                  <td colspan="3">{{ partUnitsInfo.projectName || '--' }}</td>
                </tr>
                <tr>
                  <td class="title">进场时间</td>
                  <td>{{ partUnitsInfo.createTime || '--' }}</td>
                  <td class="title">进退场情况</td>
                  <td>{{ partUnitsInfo.status || '--' }}</td>
                </tr>
                <tr v-if="partUnitsInfo.typeId == '10'">
                  <td class="title">代发委托附件</td>
                  <td colspan="3">
                    <template>
                      <span v-if="partUnitsInfo.assignmentFiles.length > 0">
                        <span>已上传</span>
                        <el-link
                          class="seeFile"
                          @click="toUploadFileOnBehalfOf()"
                          >查看</el-link
                        >
                        <contractEnclosureDialog
                          v-if="uploadContractOnBehalfOf"
                          dialogTitle="代发委托附件"
                          :tableData="partUnitsInfo.assignmentFiles"
                          @closeDialog="hiddenDialog"
                        ></contractEnclosureDialog>
                      </span>
                      <span v-else>未上传</span>
                    </template>
                  </td>
                </tr>
                <tr>
                  <td class="title">备注</td>
                  <td colspan="3">
                    {{ (partUnitsInfo.remark || '--') | filterHtml }}
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </el-col>
      </el-row>
      <div class="spacing"></div>
      <rewardAndPunishCom
        v-if="showRewardAndPunish"
        :rewardAndPunishInfo="rewardAndPunishInfo"
      ></rewardAndPunishCom>
    </div>
    <el-dialog
      title="附件"
      :visible.sync="uploadContract"
      :modal-append-to-body="false"
      :append-to-body="true"
    >
      <contractEnclosure :tableData="upLoadFile" />
    </el-dialog>
  </div>
</template>
<script>
//奖惩情况
import rewardAndPunishCom from '@/components/publicCom/rewardAndPunishCom'
export default {
  name: 'participationUnitsDetail',
  components: {
    rewardAndPunishCom,
  },
  data() {
    return {
      titleText: '企业详情',
      back: true,
      id: '',
      uscc: '',
      projectId: '',
      partUnitsInfo: {},
      upLoadFile: [], //附件
      total: {
        groupTotal: 0,
        empTotal: 0,
        onjobEmp: 0,
      },
      loginType: '', //登录类型
      isJSAdd: '', //建设方添加的显示
      uploadContract: false, //合同附件
      userType: '', //用户类型
      showRewardAndPunish: true,
      rewardAndPunishInfo: [],
      uploadContractOnBehalfOf: false,
    }
  },
  filterField: {
    filterHtml(value) {
      let reg = /<\/?.+?\/?>/g
      return value.replace(reg, '')
    },
  },
  created() {
    this.loginType = localStorage.getItem('loginType')
    this.userType = this.$store.state.userType
    this.id = this.$route.query.id
    this.uscc = this.$route.query.uscc
    this.projectId = this.$route.query.projectId
    this.isJSAdd = this.$route.query.isJSAdd
    this.getPartUnitsInfo()
    this.getGroupTotal()
  },
  methods: {
    goBack() {
      var urls, oldUrls
      if (
        this.$route.query.type == 'projectDetail' &&
        this.loginType === 'JC'
      ) {
        urls = '/home/monitorProjectManagement/projectDetail'
        oldUrls = '/home/project/projectList'
      } else if (
        this.$route.query.type == 'projectDetail' &&
        this.loginType !== 'JC'
      ) {
        urls = '/home/monitorProjectManagement/projectDetail'
        oldUrls = '/home/project/projectListQY'
      } else {
        urls = '/home/employee/projectEmployeeQY'
        oldUrls = '/home/employee/projectEmployeeQY'
      }
      this.$router.push({
        path: urls,
        query: {
          projectId: this.projectId,
        },
      })
      this.$store.commit('GOBACK_NAME', {
        oldUrl: oldUrls,
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getPartUnitsInfo() {
      this.axios({
        method: 'post',
        url: 'api-p/projectcompany/expand/finddetailbyid',
        data: {
          id: this.id,
        },
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.partUnitsInfo = response.data.result
              this.getDetail(
                this.partUnitsInfo.projectName,
                this.partUnitsInfo.companyName,
                this.partUnitsInfo.uscc
              )
              this.upLoadFile = this.partUnitsInfo.contractFiles
            } else {
              this.$message({
                message: response.data.errorMsg,
                type: 'error',
              })
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    getGroupTotal() {
      this.axios({
        method: 'post',
        url: 'api-e/cs/group/expand/findcountbyprojectid',
        data: {
          projectId: this.projectId,
          uscc: this.uscc,
        },
      })
        .then(
          (response) => {
            if (!response.data.hasError) {
              this.total.groupTotal = response.data.result.groupTotal
              this.total.empTotal = response.data.result.empTotal
              this.total.onjobEmp = response.data.result.onjobEmp
            } else {
              this.$message({
                message: response.data.errorMsg,
                type: 'error',
              })
            }
          },
          (response) => {}
        )
        .catch((error) => {})
    },
    toEmployees(state) {
      if (this.$route.query.type == '') {
        this.$router.push({
          path: '/home/employee/projectEmployeeQY',
          name: 'projectEmployeeQY',
          query: {
            projectId: this.projectId,
            uscc: this.uscc,
            isOnTheJob: state,
          },
        })
        this.$store.commit('CHANGE_SLIDER_NAME', {
          oldUrl: '/home/employee/projectEmployeeQY',
          newUrl: this.$router.currentRoute.fullPath,
        })
      } else {
        this.$router.push({
          path: '/home/monitorProjectManagement/projectDetail',
          name: 'projectDetail',
          query: {
            projectId: this.projectId,
            uscc: this.uscc,
            isOnTheJob: state,
            activeName: 'second',
          },
        })
        // this.$store.commit("CHANGE_SLIDER_NAME", {oldUrl:"/home/project/projectList",newUrl:this.$router.currentRoute.fullPath});
        if (this.loginType === 'QY' || this.loginType === 'XM') {
          //企业看板参建单位
          this.$store.commit('CHANGE_SLIDER_NAME', {
            oldUrl: '/home/project/projectListQY',
            newUrl: this.$router.currentRoute.fullPath,
          })
        } else {
          //监察看板参建单位
          this.$store.commit('CHANGE_SLIDER_NAME', {
            oldUrl: '/home/project/projectList',
            newUrl: this.$router.currentRoute.fullPath,
          })
        }
      }
    },
    toUploadFile() {
      this.upLoadFile = []
      this.getPartUnitsInfo()
      this.uploadContract = true
    },
    // toSee() {
    //     this.showRewardAndPunish = true;
    // },
    getDetail(projectName, name, uscc) {
      this.axios({
        method: 'post',
        url: 'api-r/reward/expand/findRewardForCompanyOrPerson',
        data: {
          projectName: projectName,
          companyName: name,
          uscc: uscc,
          type: 'COMPANY',
        },
      })
        .then((response) => {
          this.rewardAndPunishInfo = response.data.result
        })
        .catch((error) => {
          this.$message.error('数据获取失败')
        })
    },
    toUploadFileOnBehalfOf() {
      this.uploadContractOnBehalfOf = true
    },
    hiddenDialog() {
      this.uploadContractOnBehalfOf = false
    },
  },
}
</script>

<style lang="less" scoped>
.mainCon {
  top: 198px;
  background: none;
  padding: 0;
  .labelWidth {
    font-size: 14px;
    color: #666666;
    display: inline-block;
    height: 36px;
    text-align: right;
  }
  .information {
    font-size: 14px;
    color: #151515;
  }
  .detailInfo {
    background: #fff;
    padding: 24px;
    .bg-purple {
      width: 100%;
      // background: #F5F7FB;
      // padding: 20px;
    }
  }
  .detailInfoItem {
    margin-top: 20px;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .logoStyle {
    padding: 24px;
    background: #fff;
    .enterpriseName {
      font-size: 22px;
      color: #242c3b;
      font-weight: 700;
      margin-top: 5px;
    }
    .uscc {
      font-size: 14px;
      color: #666666;
      font-weight: 400;
      margin-top: 4px;
    }
  }
  .enterpriseLogo {
    height: 66px;
    width: 66px;
  }
  .titleInfoBox {
    height: 100%;
    // line-height: 80px;
    margin-left: 20px;
  }
}
</style>
